package com.jy.rhin.infra.feign;

import com.jy.framework.base.entity.Result;
import com.jy.rhin.domain.notification.topic.entity.TopicDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author dhl
 * @date 2022/8/24
 * @Description
 */
@Slf4j
@Service
public class QueryTopicConfigurationParametersService {

    @Resource
    QueryTopicConfigurationParametersFeign queryFeign;

    public TopicDO queryTopicSettings(String serviceAddressUrl, String topicExp){
        try {
            URI uri = new URI(serviceAddressUrl);
            Result<TopicDO> resp =  queryFeign.queryConfigurationParameters(uri, topicExp);
            if(resp.isSuccess()){
                return resp.getData();
            }else{
                return null;
            }
        } catch (URISyntaxException e) {
            log.error("获取主题配置信息服务地址错误，忽略：{}",serviceAddressUrl);
            return null;
        }catch (Exception e){
            log.error("获取主题配置信息服务异常，忽略",e.fillInStackTrace());
            return null;
        }
    }
}
